package com.kehutong.charge.service.impl;

import com.kehutong.charge.entity.ReceiptTemplates;
import com.kehutong.charge.service.ReceiptTempsService;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.orm.Pool;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.orm.jdbc.Page;
import org.coraframework.orm.jdbc.execute.entity.FindPage;

import java.util.List;

/**
 * @program: kht
 * @description: ReceiptTempsServiceImpl
 * @author: jian Ye
 * @create: 2021/8/3
 **/
public class ReceiptTempsServiceImpl implements ReceiptTempsService {

    private static final Logger logger = LoggerFactory.getLogger(ReceiptTempsServiceImpl.class);

    @Inject
    private JdbcSession jdbcSession;




    @Override
    public Page<ReceiptTemplates> findPage(JSONObject jsonObject) {
        FindPage<ReceiptTemplates> find = jdbcSession.findPage(ReceiptTemplates.class)
                .eq("deleted", false)
                .order("createTime", "desc");

        return find.page(jsonObject).exe();
    }


    @Override
    public List<ReceiptTemplates> findList(JSONObject jsonObject) {
        List<ReceiptTemplates> receiptList = jdbcSession.findArray(ReceiptTemplates.class)
                .eq("deleted", false)
                .eq("status",true)
                .exe();

        return receiptList;
    }


    @Override
    public Object save(ReceiptTemplates receiptTemplates) throws Exception {
        return jdbcSession.insert(receiptTemplates);
    }


    @Override
    public Object update(ReceiptTemplates receiptTemplates) throws Exception {
        return jdbcSession.updateById(receiptTemplates);
    }


    @Override
    public Object deleteById(String id) {
        ReceiptTemplates result = Pool.get(ReceiptTemplates.class, id);
        if (result != null) {
            result.setDeleted(true);
            jdbcSession.updateById(result);
        }
        return 1;
    }
}
